import java.awt.*;

import java.sql.*;

import javax.swing.*;

import java.awt.event.*;

public class Frame1 extends JFrame {
	JFrame jf = new JFrame();

	JPanel jp;

	JLabel jll1 = new JLabel();

	JComboBox jcb1 = new JComboBox();

	JLabel jl2 = new JLabel();

	JComboBox jcb2 = new JComboBox();

	JButton jb = new JButton();

	JTextField jtf1 = new JTextField();

	JTextField jtf2 = new JTextField();

	JTextField jtf3 = new JTextField();

	ResultSetComBoxModel rscm1 = new ResultSetComBoxModel();

	Connection con = null;

	Statement stmt1 = null;

	Statement stmt2 = null;

	ResultSet rs1 = null, rs2 = null;

	public Frame1() {
		try {
			setDefaultCloseOperation(EXIT_ON_CLOSE);

			jbInit();

			dataInit();

		} catch (Exception exception) {
			exception.printStackTrace();

		}
	}

	private void jbInit() throws Exception {

		jp = (JPanel) getContentPane();

		jp.setLayout(null);

		jf.setSize(new Dimension(500, 300));

		jf.setTitle("城市查询系统");

		jll1.setText("省名：");

		jll1.setBounds(new Rectangle(13, 29, 41, 38));

		jcb1.setBounds(new Rectangle(50, 35, 80, 24));

		jcb1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				jcb1_actionPerformed(e);

			}
		});

		jl2.setText("城市名:");

		jl2.setBounds(new Rectangle(149, 35, 49, 24));

		jcb2.setBounds(new Rectangle(209, 33, 80, 24));

		jb.setBounds(new Rectangle(320, 31, 60, 27));

		jb.setText("查询");

		jb.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				jb_actionPerformed(e);

			}
		});

		jtf1.setText("");

		jtf1.setBounds(new Rectangle(22, 100, 102, 26));

		jtf2.setText("");

		jtf2.setBounds(new Rectangle(146, 100, 102, 26));

		jtf3.setText("");

		jtf3.setBounds(new Rectangle(272, 100, 102, 26));

		jf.setVisible(true);

		jf.add(jp);

		jp.setBackground(Color.pink);

		jf.setDefaultCloseOperation(3);

		jp.add(jcb1);

		jp.add(jtf1);

		jp.add(jtf3);

		jp.add(jtf2);

		jp.add(jl2);

		jp.add(jll1);

		jp.add(jcb2);

		jp.add(jb);

	}

	private void dataInit() throws Exception{
    try{
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

    }catch(ClassNotFoundException e){}
      try{
        con = DriverManager.getConnection("jdbc:odbc:city");

        stmt1=con.createStatement(1005, 1008);

        rs1=stmt1.executeQuery("select 省名 from Capital ");

        while (rs1.next()){
          int  省号=rs1.getInt(1);

          String  省名=rs1.getString(2);

        }
        stmt2=con.CreateStatment();

        rs2=stmt2.executeQuery("select 城市名 from Capital2 where 省号=jcb1.getSelectItem()");

        while(rs2.next()){
          int 省号=rs2.getInt(1);

          int 城市号=rs2.getInt(2);

          String  城市名=rs2.getString(3);

          String 城市描述=rs2.getString(4);

        }
        con.close();

        

      }catch(Exception e){}  

       

public void jcb1_itemStateChanged(ItemEvent e) {
      

}  

 

public void jcb1_actionPerformed(ActionEvent e) {
 

} 

 

public void jb_actionPerformed(ActionEvent e) {
      if(e.getSource()==jb)

       {
          jtf1.setText(jcb1);

          jtf2.setText(jcb2);

          jtf3.setText();

       }
}
public static void main(String[] args) throws Exception 

{
      new Frame1();

}
}
}
